home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / cups / enable_sharing < prev    next >
Encoding:
Text File  |  2007-04-04  |  1.3 KB  |  66 lines

  1. #!/bin/sh -e
  2.  
  3. # Author: Martin Pitt <martin.pitt@ubuntu.com>
  4. # (C) 2005  Canonical Ltd.
  5. #
  6. # Configure CUPS IPP LAN printer sharing; this is only possible if "Listen" is
  7. # present in ports.conf (i. e. sharing_status returns 0 or 1). If the setting
  8. # changed, CUPS will be restarted.
  9. #
  10. # Argument:
  11. # 0: disable sharing 
  12. # 1: enabled sharing
  13. # Return 0 on success, or 1 on failure (prints error to stderr)
  14.  
  15. STATUS_SCRIPT=/usr/share/cups/sharing_status
  16. CONF=/etc/cups/cupsd.conf
  17.  
  18. [ -x $STATUS_SCRIPT ] || {
  19.     echo "Error: cannot execute $STATUS_SCRIPT" >&2
  20.     exit 1
  21. }
  22.  
  23. set +e
  24. $STATUS_SCRIPT
  25. STATUS=$?
  26. set -e
  27.  
  28. case "$1" in
  29.     0)
  30.     NEWVAL=Off
  31.     ;;
  32.     1)
  33.     NEWVAL=On
  34.     ;;
  35.     *)
  36.     echo "Invalid argument (must be 0 or 1)" >&2
  37.     exit 1
  38.     ;;
  39. esac
  40.  
  41. [ $STATUS = 0 -o $STATUS = 1 ] || {
  42.     echo "Error: cannot modify custom configuration" >&2
  43.     exit 1
  44. }
  45.  
  46. # nothing to do?
  47. [ $1 != $STATUS ] || exit 0
  48.  
  49.  
  50. if [ $1 = 0 ]; then
  51.     sed -ri "s/^[[:space:]]*(Port|Listen)[[:space:]]+631\\>/Listen 127.0.0.1:631/i" $CONF
  52. else
  53.     sed -ri "s/^[[:space:]]*Listen[[:space:]]+(127.0.0.1|localhost):631\\>/Listen 631/i" $CONF
  54. fi
  55.     
  56.  
  57. # restart CUPS
  58. # Automatically added by dh_installinit
  59. if [ -x "/etc/init.d/cupsys" ]; then
  60.     if [ -x /usr/sbin/invoke-rc.d ]; then
  61.     invoke-rc.d cupsys force-reload || exit 0
  62.     else
  63.     /etc/init.d/cupsys force-reload || exit 0
  64.     fi
  65. fi
  66.